package com.qfedu.yanglao20admin.sysAdmin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.yanglao20.common.CommonResult;
import com.qfedu.yanglao20.entity.sysAdmin.SysRole;
import com.qfedu.yanglao20admin.sysAdmin.param.SysRoleParam;
import com.qfedu.yanglao20admin.sysAdmin.service.SysRoleService;
import com.qfedu.yanglao20admin.sysAdmin.vo.SysRoleVO;
import com.qfedu.yanglao20admin.sysAdmin.vo.SysUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "角色管理信息")
@RestController
@RequestMapping("/sysRole")
public class SysRoleController {

    @Resource
    private SysRoleService sysRoleService;

    @ApiOperation(value = "分页展示角色管理信息", notes = "分页展示角色管理信息")
    @GetMapping("/list")
    public CommonResult<SysRoleParam> SysROleList(SysRoleParam param) {
        Page<SysRoleVO> sysRolePage = sysRoleService.pageSysRoleList(param);
        return CommonResult.success(sysRolePage);
    }

    @ApiOperation(value = "角色用户信息", notes = "角色用户信息")
    @GetMapping("/queryRoleName")
    public CommonResult queryRoleNameList(@RequestParam @ApiParam("角色用户名称") String roleName) {
        List<SysUserVO> sysUserVOS = sysRoleService.selectCountRoleName(roleName);
        return CommonResult.success(sysUserVOS);
    }

    @ApiOperation(value = "根据id查询角色管理信息", notes = "根据id查询角色管理信息")
    @GetMapping("/query")
    public CommonResult querySysRoleList(@RequestParam @ApiParam("角色管理信息id") Integer id) {
        SysRole sysRole = sysRoleService.selectById(id);
        return CommonResult.success(sysRole);
    }

    @ApiOperation(value = "根据id删除角色管理信息", notes = "根据id删除角色管理信息")
    @GetMapping("/delete")
    public CommonResult deleteSysRoleList(@RequestParam @ApiParam("角色管理信息id") Integer id) {
        sysRoleService.deleteById(id);
        return CommonResult.success();
    }


    @ApiOperation(value = "添加角色管理信息", notes = "添加角色管理信息")
    @PostMapping("/add")
    public CommonResult<SysRole> addSysRole(SysRole sysRole) {
        sysRoleService.add(sysRole);
        return CommonResult.success();
    }
    @ApiOperation(value = "修改角色管理信息", notes = "修改角色管理信息")
    @PostMapping("/update")
    public CommonResult<SysRole> updateSysRole(SysRole sysRole) {
        sysRoleService.updateSysRole(sysRole);
        return CommonResult.success();
    }
}
